import axios from "axios";
import { message } from "ant-design-vue";

const myAxios = axios.create({
  baseURL: "http://127.0.0.1:8123",
  timeout: 5000,
  withCredentials: true,
})


myAxios.interceptors.request.use(
  config => {
    return config;
  },
  error => {
    return Promise.reject(error);
  }
)

myAxios.interceptors.response.use(
  response => {
    if (response.status === 40100) {
      if (
        !response.request.responseURL.includes('user/get/login') &&
        !window.location.pathname.includes('user/login')
      ) {
        message.warning('登录状态已过期，请重新登录');
        window.location.href = `/user/login?redirect=${window.location.href}`;
      }
    }
    return response;
  },
  error => {
    return Promise.reject(error);
  }
)

export default myAxios;
